import socket

def subdomain_boom(domain):
    # 创建一个字典类型存放指定的子域名和对应的ip地址
    try:
        domainDict = {}
        domainIP = socket.gethostbyname(domain)
#       domainDict[domain] = domainIP
        domainList = domain.split('.', 1)
        with open("subdomains.txt", "r") as f:
            for line in f:
                # 将指定文件的子域名的头与指定域名的格式进行拼接成子域名
                subdomain = line.rstrip() + "." + domainList[1]
                try:
                    # 根据子域名来获取主机ip地址
                    subdomainIP = socket.gethostbyname(subdomain)
                    # 将子域名和对应的IP地址存放到字典类型中
                    domainDict[subdomain] = subdomainIP
                except socket.gaierror:
                    print(f"无法解析子域名: {subdomain}")
        # 循环输出字典类型中的元素
        print("子域名以及对应的ip地址为：")
        for subdomain, ip in domainDict.items():
            print(f"{subdomain} -> {ip}")
    except socket.gaierror:
        print("域名解析失败")
    except Exception as e:
        print(f"发生错误: {e}")

if __name__ == '__main__':
    domain = input("请输入目标域名：")
    subdomain_boom(domain)

